'''
Created on 08/04/2011

@author: Eran_Z

Google search (num results), based on Dima's implementation
currently uses deprecated API
'''

import json
import urllib

#N = 25270000000L #25.27 billion, roughly google's index size. Should be reduced for other engines.
N = 1870000000L #roughly the index of the deprecated API

def googleSearchResults(searchfor):
    query = urllib.urlencode({'q': searchfor})
    
    url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s'%query
    search_response = urllib.urlopen(url)
    search_results = search_response.read()
    results = json.loads(search_results)
    data = results['responseData']
    ret =  data['cursor']['estimatedResultCount']
    
    return long(ret)
